#include <iostream>
#include <vector>
using namespace  std;

class Solution {
public:
    int movingCount(int m, int n, int k) {
        // if(computeSum(m, n) > k)
        //     return 0;
        int count = 0;
        vector<bool> pre(n, true);
        vector< vector<bool> > map(m, pre);
        count = myCount(0, 0, map, k);
        return count;
    }

    int myCount(int m, int n, vector< vector<bool> > map, int k)
    {
        if(computeSum(m, n) > k  || m >= map.size() || n >= map[0].size() || m < 0 || n<0 || map[m][n] == false)
            return 0;
        int count = 1;
        map[m][n] = false;
        count += myCount(m - 1, n, map, k);
        count += myCount(m, n - 1, map, k);
        count += myCount(m + 1, n, map, k);
        count += myCount(m, n + 1, map, k);
        return count;
    }
    int computeSum(int m, int n)
    {
        int result = 0;
        while( m != 0)
        {
            result += m%10;
            m = m/10;
        }

        while( n!= 0)
        {
            result += n%10;
            n /=10;
        }
        return result;
    }
};
int main() {
//    if(1 && int a = 1 == 1 )
        cout<<"aba"<<endl;
//    vector<bool> a(5,true);
//    vector< vector<bool> > b(4,a);
//    Solution sol;
//    int count = sol.movingCount(2,2,17);
//    std::cout << "Hello, World!" << count<< std::endl;
    return 0;
}
